package com.wswy.wzcx.ui.wzdb

import android.content.Context
import android.graphics.Color
import android.support.design.widget.BottomSheetBehavior
import android.support.design.widget.BottomSheetDialog
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import com.wswy.wzcx.R
import com.wswy.wzcx.ui.other.ClickUtils
import kotlinx.android.synthetic.main.dialog_layout_choose_cert.*

internal class ChooseCertDialog(context: Context, val key: String?) : BottomSheetDialog(context), View.OnClickListener {

    private val imgKeyMap = hashMapOf(Pair("DLOF", R.drawable.pic_jiashizhengzhengmian),
            Pair("DLOB", R.drawable.pic_jiashizhengbeimian),
            Pair("DLCF", R.drawable.pic_zhunjiachexingdaihao),
            Pair("VLOF", R.drawable.pic_xingshizhengzhengmian),
            Pair("VLCF", R.drawable.pic_xingshizhengfanmian),
            Pair("JJ", R.drawable.pic_chezhuzipai))


    var onChooseListener: OnChooseListener? = null

    override fun onClick(v: View) {

        if (ClickUtils.isFastClick()) {
            return
        }

        when (v.id) {
            R.id.tv_from_camera -> {
                onChooseListener?.onStartCamera()
                dismiss()
            }
            R.id.tv_from_gallery -> {
                onChooseListener?.onStartGallery()
                dismiss()
            }
            R.id.tv_cancel -> {
                dismiss()
            }
        }
    }


    internal interface OnChooseListener {
        fun onStartCamera()
        fun onStartGallery()
    }

    init {
        val inflate = LayoutInflater.from(context).inflate(R.layout.dialog_layout_choose_cert, null)
        val img = inflate.findViewById<ImageView>(R.id.img_card_example)
        if (key != null && imgKeyMap.containsKey(key)) {
            img.setImageResource(imgKeyMap[key]!!)
        } else {
            img.visibility = View.GONE
        }
        setContentView(inflate)
        tv_from_camera.setOnClickListener(this)
        tv_from_gallery.setOnClickListener(this)
        tv_cancel.setOnClickListener(this)


        findViewById<View>(android.support.design.R.id.design_bottom_sheet)?.let {
            it.setBackgroundColor(Color.TRANSPARENT)
            val behavior = BottomSheetBehavior.from(it)
            behavior.state = BottomSheetBehavior.STATE_EXPANDED
            behavior.setPeekHeight(0)
        }

    }


}